package rad.framework.mda.generator.template.main.webapp.webinf;

import java.util.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.uml2.uml.*;

public class JsfFacesConfig
{
  protected static String nl;
  public static synchronized JsfFacesConfig create(String lineSeparator)
  {
    nl = lineSeparator;
    JsfFacesConfig result = new JsfFacesConfig();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<?xml version=\"1.0\"?>" + NL + "<faces-config version=\"1.2\" " + NL + "\txmlns=\"http://java.sun.com/xml/ns/javaee\"" + NL + "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + NL + "\txsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd\">" + NL + "" + NL + "\t<!-- CRUD Navigation -->" + NL + "\t";
  protected final String TEXT_2 = NL + "\t<!-- navigation rules for ";
  protected final String TEXT_3 = " " + NL + "\t-->" + NL + "\t<navigation-rule>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>create";
  protected final String TEXT_4 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_5 = "/Edit.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>find";
  protected final String TEXT_6 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_7 = "/Search.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>view";
  protected final String TEXT_8 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_9 = "/View.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>edit";
  protected final String TEXT_10 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_11 = "/Edit.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>";
  protected final String TEXT_12 = "Charts</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_13 = "/Charts.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>excel";
  protected final String TEXT_14 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/xls/";
  protected final String TEXT_15 = "/";
  protected final String TEXT_16 = ".xhtml</to-view-id>" + NL + "\t\t</navigation-case>" + NL + "\t</navigation-rule>" + NL + "    ";
  protected final String TEXT_17 = NL + NL + "\t<!-- Pageflow Navigation -->" + NL + "\t";
  protected final String TEXT_18 = NL + "\t<!-- navigation rules for ";
  protected final String TEXT_19 = " -->" + NL + "\t<navigation-rule>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>start";
  protected final String TEXT_20 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_21 = "/Pageflow.xhtml</to-view-id>" + NL + "\t\t\t<redirect/>" + NL + "\t\t</navigation-case>" + NL + "\t</navigation-rule>";
  protected final String TEXT_22 = NL + "\t<navigation-rule>" + NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>goTo";
  protected final String TEXT_23 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_24 = "/";
  protected final String TEXT_25 = ".xhtml</to-view-id>" + NL + "\t\t</navigation-case>" + NL + "\t</navigation-rule>" + NL + "\t<navigation-rule>" + NL + "\t\t<from-view-id>/jsf/";
  protected final String TEXT_26 = "/";
  protected final String TEXT_27 = ".xhtml</from-view-id>";
  protected final String TEXT_28 = NL + "\t\t<navigation-case>" + NL + "\t\t\t<from-outcome>";
  protected final String TEXT_29 = "</from-outcome>" + NL + "\t\t\t<to-view-id>/jsf/";
  protected final String TEXT_30 = "/";
  protected final String TEXT_31 = ".xhtml</to-view-id>" + NL + "\t\t</navigation-case>";
  protected final String TEXT_32 = NL + "\t</navigation-rule>" + NL + "    ";
  protected final String TEXT_33 = NL + "</faces-config>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    Model uml2Model = (Model) argument;
    stringBuffer.append(TEXT_1);
    for (Iterator i=ClassHelper.getClasses(uml2Model).iterator(); i.hasNext();) { org.eclipse.uml2.uml.Class element = (org.eclipse.uml2.uml.Class)i.next();
    if (StereotypeHelper.isStereotypeApplied(element,"javax.persistence.Entity")) {
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(element.getQualifiedName()));
    stringBuffer.append(TEXT_3);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(NameHelper.uncapName(element.getName()));
    stringBuffer.append(TEXT_12);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_16);
    }}
    stringBuffer.append(TEXT_17);
    for (Iterator<Region> i=JsfHelper.getPageflows(uml2Model); i.hasNext();) { Region region = (Region)i.next();
    stringBuffer.append(TEXT_18);
    stringBuffer.append(NameHelper.getQualifiedName(region.getQualifiedName()));
    stringBuffer.append(TEXT_19);
    stringBuffer.append(NameHelper.removeSpaces(region.getName()));
    stringBuffer.append(TEXT_20);
    stringBuffer.append(NameHelper.removeSpaces(region.getName()));
    stringBuffer.append(TEXT_21);
    for (Iterator<State> j=JsfHelper.getPages(region); j.hasNext();) { State state = (State)j.next();
    stringBuffer.append(TEXT_22);
    stringBuffer.append(NameHelper.removeSpaces(state.getName()));
    stringBuffer.append(TEXT_23);
    stringBuffer.append(NameHelper.removeSpaces(region.getName()));
    stringBuffer.append(TEXT_24);
    stringBuffer.append(NameHelper.removeSpaces(state.getName()));
    stringBuffer.append(TEXT_25);
    stringBuffer.append(NameHelper.removeSpaces(region.getName()));
    stringBuffer.append(TEXT_26);
    stringBuffer.append(NameHelper.removeSpaces(state.getName()));
    stringBuffer.append(TEXT_27);
    for (Iterator<Transition> k=state.getOutgoings().iterator(); k.hasNext();) { Transition t = (Transition)k.next();
    stringBuffer.append(TEXT_28);
    stringBuffer.append(NameHelper.removeSpaces(t.getName()));
    stringBuffer.append(TEXT_29);
    stringBuffer.append(NameHelper.removeSpaces(region.getName()));
    stringBuffer.append(TEXT_30);
    stringBuffer.append(NameHelper.removeSpaces(t.getTarget().getName()));
    stringBuffer.append(TEXT_31);
    }
    stringBuffer.append(TEXT_32);
    }}
    stringBuffer.append(TEXT_33);
    return stringBuffer.toString();
  }
}
